package stack;

import linkedList.CandyLinkedList;

public class CandyLinkedListStack<E> implements CandyStack<E> {
	private CandyLinkedList<E> list;
	
	public CandyLinkedListStack() {
	}

	@Override
	public int getSize() {
		return list.getSize();
	}

	@Override
	public boolean isEmpty() {
		return list.isEmpty();
	}

	@Override
	public void push(E e) {
		list.addFirst(e);
	}

	@Override
	public E pop() {
		return list.removeFirst();
	}

	@Override
	public E peak() {
		return list.getFirst();
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder("CandyLinkedStack: top [ ");
		return sb.append(list + " ]").toString();
	}

	public static void main(String[] args) {
		CandyLinkedListStack<Integer> stack = new CandyLinkedListStack(); 
		for(int i = 0; i < 5; i++) {
			stack.push(i);
			System.out.println(stack);
		}
		System.out.println("出栈元素：" + stack.pop());
		System.out.println(stack);
	}
}
